Fix date/time manipulations in jira_agent.rb

During testing, I figured out that jira doesn't understand
timezones in JQL. Because of this I have to introduce a
workaround that fetches issues 24 h earlier that the requested
date and then filters out unnecessary ones based on the
value of 'updated' field.

Konstantin Nazarov 11 years ago
parent
commit
8ea394f53f
1 changed files with 15 additions and 2 deletions
  1. 15 2
      app/models/agents/jira_agent.rb

+ 15 - 2
app/models/agents/jira_agent.rb

@@ -61,7 +61,13 @@ module Agents
61 61
         issues = get_issues(last_run)
62 62
 
63 63
         issues.each do |issue|
64
-          create_event :payload => issue
64
+          updated = Time.parse(issue['fields']['updated'])
65
+
66
+          # this check is more precise than in get_issues()
67
+          # see get_issues() for explanation
68
+          if updated > last_run then
69
+            create_event :payload => issue
70
+          end
65 71
         end
66 72
 
67 73
         memory[:last_run] = current_run
@@ -90,13 +96,20 @@ module Agents
90 96
       startAt = 0
91 97
       issues = []
92 98
 
99
+      # JQL doesn't have an ability to specify timezones
100
+      # Because of this we have to fetch issues 24 h
101
+      # earlier and filter out unnecessary ones at a later
102
+      # stage. Fortunately, the 'updated' field has GMT
103
+      # offset
104
+      since -= 24*60*60
105
+
93 106
       jql = ""
94 107
 
95 108
       if !options[:jql].empty? && since then 
96 109
         jql = "(#{options[:jql]}) and updated >= '#{since.strftime('%Y-%m-%d %H:%M')}'"
97 110
       else
98 111
         jql = options[:jql] if !options[:jql].empty?
99
-        jql = "updatedd >= '#{since.strftime('%Y-%m-%d %H:%M')}'" if since
112
+        jql = "updated >= '#{since.strftime('%Y-%m-%d %H:%M')} GMT'" if since
100 113
       end
101 114
 
102 115